import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import moment from 'moment';
const { Link } = router;

export default (self, lecturers, examList) => [
    {
        title: 'ID',
        name: 'id',
        formItem: {'type': 'hidden'}
    },
    {
        title: '名称',
        name: 'name',
        tableItem: {},
        formItem: {
            rules: [
                {
                    required: true,
                    message: '请填写名称'
                }
            ]
        },
        searchItem: {
        }
    },{
        title: '简介',
        name: 'description',
        tableItem: {},
        formItem: {rules: [
                {
                    required: true,
                    message: '请填写简介'
                }
            ]},
    },{
        title: '主讲老师',
        name: 'lecturerList',
        tableItem: {
            render: text => text.map(item => item.realname).join(',')
        },
        formItem: {
            type: 'transfer',
            modal: true,
            dataSource: lecturers,
            normalize: value => value.map(item => item.id),
            rules: [
                {
                    required: true,
                    message: '请选择主讲老师'
                }
            ]
        }
    },{
        title: '课时',
        name: 'duration',
        tableItem: {
            render: text => text
        },
        formItem: {
            type: 'number',
            rules: [
                {
                    required: true,
                    message: '请填写课时'
                }
            ]

        },
        searchItem: {}
    },{
        title: '顺序',
        name: 'orderNumber',
        formItem: {
            type: 'number',
            rules: [],
        },
    },{
        title: '推荐',
        name: 'isRecommend',
        dict: [{ code: '0', codeName: '否' }, { code: '1', codeName: '是' }],
        tableItem: {
            render: text => text ? '是': '否'
        },
        // formItem: {
        //     type: 'select'
        // },
    },
    {
        title: '创建时间',
        name: 'createTime',
        tableItem: {
            render: text =>
                moment.utc(text).format('YYYY-MM-DD HH:mm')
            // moment.utc(text).toDate().toLocaleDateString()
        },
        // formItem: {
        //     type: 'datetime'
        // },
    },
    {
        title: '开始时间',
        name: 'startTime',
        tableItem: {
        },
        formItem: {
            type: 'datetime',
            format: 'YYYY-MM-DD HH:mm',
            rules: [
                {
                    required: true,
                    message: '请填写开始时间'
                }
            ]
        },
    },{
        title: '视频',
        name: 'video',
        formItem: {
            type: 'upload',
            fileTypes: ['.mp4', '.avi', '.mp3', '.wmv'],
            maxFileSize: 1024* 1024* 300, // 最大限制 300M
            listType: 'picture',
            max: 1,
            onRemove: (file)=>{
                if(!file.hasOwnProperty('originFileObj')){
                    self.handleDocumentDelete(file.uid);
                }
            },
            progress:{
                strokeColor:{
                    '0%': '#108ee9',
                    '100%': '#87d068'
                },
                strikeWidth: 3,
                format: percent => `${parseFloat(percent.toFixed(2))}%`,
            },
            rules: [
                {required: true, message: '请上传视频'}
            ]
        },
    },{ title: '课次封面',
        name: 'cover',
        formItem: {
            type: 'upload',
            action: '/api/lesson/upload/lessonCover',
            fileName: 'file',
            fileTypes: ['.png', '.jpg', '.gif'],
            listType: 'picture',
            normalize: value => {
                return [
                    {
                        uid: -1,
                        thumbUrl: value
                    }
                ];
            },
            max:1,
            multiple: false,
            // showUploadList: false,
            rules: [
                {
                    required: true,
                    message: '请上传封面'
                }
            ]
        }
    },{
        title: '附件',
        name: 'files',
        formItem: {
            type: 'upload',
            fileTypes: ['.ppt', 'pptx','.xls', 'xlsx', '.doc', '.docx','.txt', 'jpg', 'gif', 'png', '.jpeg', '.pdf'],
            maxFileSize: 1024* 1024* 50, // 最大限制 50M
            listType: 'text',
            multiple: true,
            max: 10,
            onRemove: (file)=>{
                if(!file.hasOwnProperty('originFileObj')){
                    self.handleDocumentDelete(file.uid);
                }
            },
        },
    },{
        title: '测试',
        name: 'exams',
        dict: examList.map(item => {return {code : item.id, codeName: item.name}}),
        formItem: {
            type: 'select'
        }
    },
    {
        title: '操作',
        tableItem: {
            width: 180,
            render: (text, record) => (
                <DataTable.Oper>
                    <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
                        <Icon type="edit" />
                    </Button>
                    <Button tooltip="删除" onClick={e => self.onDelete(record)}>
                        <Icon type="trash" />
                    </Button>
                    {/*<Button tooltip="测试" onClick={e => self.manageExam(record)}>*/}
                    {/*    <Icon type="HighlightOutlined" antd />*/}
                    {/*</Button>*/}
                </DataTable.Oper>
            )
        }
    }
];
